<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Controller for Admin
 * 
 * @package libraries
 * @author  Dac Diep Vuong 
 */
class Admin_Controller extends Controller
{
    /**
     * Var Title
     * 
     * @var String
     */
    protected $title = '';
    
    function __construct() {      
        parent::__construct();     
        if(isset($_SESSION)) {
            print_r($_SESSION); die;
        }
            
        $userSession = $this->session->userdata('is_logged_in');      
        //$userSession = $_SESSION[SESSION_NAME]['is_logged_in'];
        if(!$userSession && $this->router->class == 'admin' && $this->router->method != 'login'){
            redirect('admin/user/login');
        }
        elseif($userSession && $this->router->class == 'admin' && $this->router->method == 'login'){
            redirect('admin/home');
        }  
        // Set layout
        $this->template->layout = 'admin';
        // Set css
        $this->template->addCss('admin.styles.css');
        $this->template->addCss('admin.tabmenu.css');
        // Set js
        $this->template->addJsCode('var SITE_URL = \'http://mapps.vn/\'; var URI_URL = \'/admin/home\';', 'TOP'); 
        $this->template->addJs('jquery/jquery-1.4.2.min.js', 'TOP'); 
    }
    
    /**
     * Content 
     * 
     * @param Array $data
     * @param String $file 
     */
    protected function setContent($data = false, $file) {
        if(!$file) {
            $file = $this->router->method;
        }
        if(isset($data['title_for_layout'])) {
            $this->title = $data['title_for_layout'] .' | MAPPS.VN';
            unset($data['title_for_layout']);
        }
        else {
            $this->title = $this->title .' | MAPPS.VN';
        }
        $this->template->data = array(
            'content_for_layout' => $this->load->view($file, $data, true),
            'title_for_layout' => $this->title
        );
    }
    
    /**
     * Get UserInfo
     * 
     */
    public function getUserInfo() {
        
    }
}
?>
